<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>sident</title>
  </head>
  <body bgcolor="#FFFFFF">
    <center>Scilab Function</center>
    <div align="right">Last update : April 1999</div>
    <p>
      <b>sident</b> -  discrete-time state-space realization and Kalman gain</p>
    <h3>
      <font color="blue">Calling Sequence</font>
    </h3>
    <dl>
      <dd>
        <tt>   [(A,C)(,B(,D))(,K,Q,Ry,S)(,rcnd)] = sident(meth,job,s,n,l,R(,tol,t,Ai,  </tt>
      </dd>
      <dd>
        <tt>                                              Ci,printw))  </tt>
      </dd>
    </dl>
    <h3>
      <font color="blue">Parameters</font>
    </h3>
    <ul>
      <li>
        <tt>
          <b>meth</b>
        </tt>: integer option to determine the method to use:<ul>
          <li>
            <tt>
              <b>=  </b>
            </tt>1 : MOESP method with past inputs and outputs;</li>
          <li>
            <tt>
              <b>=  </b>
            </tt>2 : N4SID method;</li>
          <li>
            <tt>
              <b>=  </b>
            </tt>3 : combined method: A and C via MOESP, B and D via N4SID.</li>
        </ul>
      </li>
      <li>
        <tt>
          <b>job</b>
        </tt>: integer option to determine the calculation to be performed:<ul>
          <li>
            <tt>
              <b>=  </b>
            </tt>1 : compute all system matrices, A, B, C, D;</li>
          <li>
            <tt>
              <b>=  </b>
            </tt>2 : compute the matrices A and C only;</li>
          <li>
            <tt>
              <b>=  </b>
            </tt>3 : compute the matrix B only;</li>
          <li>
            <tt>
              <b>=  </b>
            </tt>4 : compute the matrices B and D only.</li>
        </ul>
      </li>
      <li>
        <tt>
          <b>s</b>
        </tt>: the number of block rows in the processed input and output block Hankel matrices.  s &gt; 0.</li>
      <li>
        <tt>
          <b>n</b>
        </tt>: integer, the order of the system</li>
      <li>
        <tt>
          <b>l</b>
        </tt>: integer, the number of the system outputs</li>
      <li>
        <tt>
          <b>R</b>
        </tt>: the 2*(m+l)*s-by-2*(m+l)*s part of  R  contains the processed upper triangular factor  R  from the QR factorization of the concatenated block-Hankel matrices, and further details needed for computing system matrices.</li>
      <li>
        <tt>
          <b>tol</b>
        </tt>: (optional) tolerance used for estimating the rank of matrices. If  tol &gt; 0,  then the given value of  tol  is used as a lower bound for the reciprocal condition number; an m-by-n matrix whose estimated condition number is less than  1/tol  is considered to be of full rank. Default:    m*n*epsilon_machine where epsilon_machine is the relative machine precision.</li>
      <li>
        <tt>
          <b>t</b>
        </tt>: (optional) the total number of samples used for calculating the covariance matrices.  Either t = 0, or t &gt;= 2*(m+l)*s. This parameter is not needed if the covariance matrices and/or the Kalman predictor gain matrix are not desired. If t = 0, then K, Q, Ry, and S are not computed. Default:    t = 0.</li>
      <li>
        <tt>
          <b>Ai</b>
        </tt>: real matrix</li>
      <li>
        <tt>
          <b>Ci</b>
        </tt>:  real matrix</li>
      <li>
        <tt>
          <b>printw</b>
        </tt>: (optional) switch for printing the warning messages.<ul>
          <li>
            <tt>
              <b>=  </b>
            </tt>1:  print warning messages;</li>
          <li>
            <tt>
              <b>=  </b>
            </tt>0:  do not print warning messages.</li>
        </ul>
        <p>
    Default:    printw = 0.
  </p>
      </li>
      <li>
        <tt>
          <b>A</b>
        </tt>: real matrix</li>
      <li>
        <tt>
          <b>C</b>
        </tt>: real matrix</li>
      <li>
        <tt>
          <b>B</b>
        </tt>: real matrix</li>
      <li>
        <tt>
          <b>D</b>
        </tt>: real matrix</li>
      <li>
        <tt>
          <b>K</b>
        </tt>: real matrix, kalman gain</li>
      <li>
        <tt>
          <b>Q</b>
        </tt>: (optional) the n-by-n positive semidefinite state covariance matrix used as state weighting matrix when computing the Kalman gain.</li>
      <li>
        <tt>
          <b>RY</b>
        </tt>: (optional) the l-by-l positive (semi)definite output covariance matrix used as output weighting matrix when computing the Kalman gain.</li>
      <li>
        <tt>
          <b>S</b>
        </tt>: (optional) the n-by-l state-output cross-covariance matrix used as cross-weighting matrix when computing the Kalman gain.</li>
      <li>
        <tt>
          <b>rcnd</b>
        </tt>: (optional) vector of length lr, containing estimates of the reciprocal condition numbers of the matrices involved in rank decisions, least squares, or Riccati equation solutions, where   lr = 4,  if Kalman gain matrix K is not required, and  lr = 12, if Kalman gain matrix K is required.</li>
    </ul>
    <h3>
      <font color="blue">Description</font>
    </h3>
    <p>
    SIDENT function for computing a discrete-time state-space realization
    (A,B,C,D) and Kalman gain K using SLICOT routine IB01BD.</p>
    <pre>

                 [A,C,B,D] = sident(meth,1,s,n,l,R)
   [A,C,B,D,K,Q,Ry,S,rcnd] = sident(meth,1,s,n,l,R,tol,t)
                     [A,C] = sident(meth,2,s,n,l,R)
                         B = sident(meth,3,s,n,l,R,tol,0,Ai,Ci)
         [B,K,Q,Ry,S,rcnd] = sident(meth,3,s,n,l,R,tol,t,Ai,Ci)
                     [B,D] = sident(meth,4,s,n,l,R,tol,0,Ai,Ci)
       [B,D,K,Q,Ry,S,rcnd] = sident(meth,4,s,n,l,R,tol,t,Ai,Ci)
   
    </pre>
    <p>
    SIDENT computes a state-space realization (A,B,C,D) and the Kalman
    predictor gain K of a discrete-time system, given the system
    order and the relevant part of the R factor of the concatenated 
    block-Hankel matrices, using subspace identification techniques 
    (MOESP, N4SID, or their combination).</p>
    <p>
       The model structure is :</p>
    <pre>

         x(k+1) = Ax(k) + Bu(k) + Ke(k),   k &gt;= 1,
         y(k)   = Cx(k) + Du(k) + e(k),
   
    </pre>
    <p>
       where  
    x(k)  is the  n-dimensional state vector (at time k),</p>
    <p>
    u(k)  is the  m-dimensional input vector,</p>
    <p>
    y(k)  is the  l-dimensional output vector,</p>
    <p>
    e(k)  is the  l-dimensional disturbance vector,</p>
    <p>
    and  A, B, C, D, and K  are real matrices of appropriate dimensions.</p>
    <h3>
      <font color="blue">Comments</font>
    </h3>
    <dl>
      <p>
    1. The n-by-n system state matrix A, and the p-by-n system output  matrix C are computed for job &lt;= 2.</p>
      <p>
    2. The n-by-m system input matrix B is computed for job &lt;&gt; 2.</p>
      <p>
    3. The l-by-m system matrix D is computed for job = 1 or 4.</p>
      <p>
    4. The n-by-l Kalman predictor gain matrix K and the covariance matrices Q, Ry, and S are computed for t &gt; 0.</p>
    </dl>
    <h3>
      <font color="blue">Examples</font>
    </h3>
    <pre>

//generate data from a given linear system
A = [ 0.5, 0.1,-0.1, 0.2;
      0.1, 0,  -0.1,-0.1;      
     -0.4,-0.6,-0.7,-0.1;  
      0.8, 0,  -0.6,-0.6];      
B = [0.8;0.1;1;-1];
C = [1 2 -1 0];
SYS=syslin(0.1,A,B,C);
nsmp=100;
U=prbs_a(nsmp,nsmp/5);
Y=(flts(U,SYS)+0.3*rand(1,nsmp,'normal'));

S = 15;
N = 3;
METH=1;
[R,N1] = findR(S,Y',U',METH);
[A,C,B,D,K] = sident(METH,1,S,N,1,R);
SYS1=syslin(1,A,B,C,D);
SYS1.X0 = inistate(SYS1,Y',U');

Y1=flts(U,SYS1);
xbasc();plot2d((1:nsmp)',[Y',Y1'])



METH = 2;
[R,N1,SVAL] = findR(S,Y',U',METH);
tol = 0;
t = size(U',1)-2*S+1;

[A,C,B,D,K] = sident(METH,1,S,N,1,R,tol,t)
SYS1=syslin(1,A,B,C,D)
SYS1.X0 = inistate(SYS1,Y',U');

Y1=flts(U,SYS1);
xbasc();plot2d((1:nsmp)',[Y',Y1'])
 
  </pre>
    <h3>
      <font color="blue">See Also</font>
    </h3>
    <p>
      <a href="findBD.htm">
        <tt>
          <b>findBD</b>
        </tt>
      </a>,&nbsp;&nbsp;<a href="sorder.htm">
        <tt>
          <b>sorder</b>
        </tt>
      </a>,&nbsp;&nbsp;</p>
    <h3>
      <font color="blue">Author</font>
    </h3>
    <p>   V. Sima, Research Institute for Informatics, Bucharest, Oct. 1999. 
  Revisions: May 2000, July 2000. 
 </p>
  </body>
</html>
